package il.ac.technion.wiki.api.wikidocument;

import il.ac.technion.wiki.api.wikidocument.content.ContentImporter;
import il.ac.technion.wiki.api.wikidocument.metadata.Metadata;

import java.util.Map;

/**
 *	Represents data that is relevant to a specific version.
 */
public class VersionData {
	private Integer version = null;
	private ContentImporter contentImporter = null;
	Metadata metadata = null;

	/**
	 * Use this constructor when your document doesn't contain metadata
	 */
	public VersionData(Integer version, ContentImporter ci) {
		if (ci == null)
			throw new IllegalArgumentException("content shouldn't be null");
		this.version = version;
		this.contentImporter = ci;
	}
	
	public VersionData(Integer version, ContentImporter ci, Map<String, String> metadata) {
		if ((ci == null) || (metadata == null))
			throw new IllegalArgumentException("null argument");
		this.version = version;
		this.contentImporter = ci;
		this.metadata = new Metadata(metadata);
	}

	public String getContent() {
		return contentImporter.asString();
	}

	public Integer getVersion() {
		return version;
	}

	/**
	 * @return versions's metadata, may be null if the version doesn't include a metadata
	 */
	public Map<String, String> getMetadata() {
		return (metadata != null) ? metadata.getFields() : null;
	}

	public ContentImporter getContentImporter() {
		return this.contentImporter;
	}

	public String getMetadataField(String field){
		return metadata.getField(field);
	}
}
